function createAJAX(){
	var xmlhttp;
	if(window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	var url = "loginAction.m";
	var para = "userName="+document.getElementById("userName").value
		+"&userPassword="+document.getElementById("userPassword").value;
	cbfunc = function(){
		if(xmlhttp.readyState == 4){
			if(xmlhttp.status == 200){
				document.getElementById("result").innerHTML = xmlhttp.responseText;
			}
			else
				document.getElementById("result").innerHTML = xmlhttp.statusText;
		}
	};
	
	xmlhttp.onreadystatechange = cbfunc;
	xmlhttp.open("POST",url,true);//中文要用urlEncode
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(para);
}

function findCities(sheng){
	var xmlhttp;
	if(window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	var url = "shengshiAction.m";
	var para = "sheng="+sheng;
	cbfunc = function(){
		if(xmlhttp.readyState == 4){
			if(xmlhttp.status == 200){
				var i;
				document.getElementById("select_shi").options.length = 0;
				var shires = xmlhttp.responseText;
				//var shilist = new Array;
				var shilist = shires.split(",");
				for(i=0;i<shilist.length;i=i+2){
					document.getElementById("select_shi").options.add(new Option(shilist[i+1],shilist[i]));
				}
				document.getElementById("select_shi").options[0].selected = true;
			}
			else
				document.getElementById("result").innerHTML = xmlhttp.statusText;
		}
	};
	
	xmlhttp.onreadystatechange = cbfunc;
	xmlhttp.open("POST",url,true);//中文要用urlEncode
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(para);
}

function selectShengshi(){
	document.getElementById("select_shengshi").disabled = false;
	document.getElementById("select_shengxian").disabled = true;
	document.getElementById("select_shixian").disabled = true;
	document.getElementById("select_shi").disabled = true;
}

function selectGuo(){
	document.getElementById("select_shengshi").disabled = true;
	document.getElementById("select_shengxian").disabled = true;
	document.getElementById("select_shixian").disabled = true;
	document.getElementById("select_shi").disabled = true;
}

function selectShengxian(){
	document.getElementById("select_shengshi").disabled = true;
	document.getElementById("select_shengxian").disabled = false;
	document.getElementById("select_shixian").disabled = true;
	document.getElementById("select_shi").disabled = true;
}

function selectShixian(){
	document.getElementById("select_shengshi").disabled = true;
	document.getElementById("select_shengxian").disabled = true;
	document.getElementById("select_shixian").disabled = false;
	document.getElementById("select_shi").disabled = false;
}

function sureRegion(){
	var xmlhttp;
	if(window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	var url = "regionSVGAction.m";
	var para = "sheng=none&shi=none";
	
	if(document.getElementById("radio_guo").checked==true)
		para="sheng=guo&shi=guo";
	else if(document.getElementById("radio_shengshi").checked==true)
		para="sheng="+document.getElementById("select_shengshi").options[document.getElementById("select_shengshi").options.selectedIndex].value+
			"&shi=shi";
	else if(document.getElementById("radio_shengxian").checked==true)
		para="sheng="+document.getElementById("select_shengxian").options[document.getElementById("select_shengxian").options.selectedIndex].value+
			"&shi=xian";
	else if(document.getElementById("radio_shixian").checked==true)
		para="sheng="+document.getElementById("select_shixian").options[document.getElementById("select_shixian").options.selectedIndex].value+
			"&shi="+document.getElementById("select_shi").options[document.getElementById("select_shi").options.selectedIndex].value;
	cbfunc = function(){
		
		if(xmlhttp.readyState == 4){
			
			if(xmlhttp.status == 200){
				
				document.getElementById("map").innerHTML = xmlhttp.responseText;
				//------------------------------------------------------------------
				var svgElement = document.getElementById('SvgElement');
				
				var viewBox = svgElement.getAttribute('viewBox');
				var viewBoxValues = viewBox.split(' ');
				var pList = $("path");
				
				var min_X=1000.0,min_Y=1000.0,max_X=0.0,max_Y=0.0;
				var temp1,temp2,temp3,temp4;
				var v1,v2,v3,v4;

				pList.each(function() {

					temp1 = $(this).attr("minx");
					temp2 = $(this).attr("miny");
					temp3 = $(this).attr("maxx");
					temp4 = $(this).attr("maxy");
//					alert(temp1);
					if(temp1 < min_X)
						min_X = temp1;
					if(temp2 < min_Y)
						min_Y = temp2;
					if(temp3 > max_X)
						max_X = temp3;
					if(temp4 > max_Y)
						max_Y = temp4;
				});
//				alert(min_X+" "+min_Y+" "+max_X+" "+max_Y);
				v1=parseFloat(viewBoxValues[0]);
				v2=parseFloat(viewBoxValues[1]);
				v3=parseFloat(viewBoxValues[2]);
				v4=parseFloat(viewBoxValues[3]);
				
				viewBoxValues[0] = min_X-3;//此处后面数字的加减是调整底图放大后所在位置的参数
				viewBoxValues[1] = min_Y-5;
				viewBoxValues[2] = max_X-min_X+10;
				viewBoxValues[3] = max_Y-min_Y+10;
//				alert(viewBoxValues[0]+" "+viewBoxValues[1]+" "+viewBoxValues[2]+" "+viewBoxValues[3]);
				svgElement.setAttribute('viewBox', viewBoxValues.join(' '));// 将修改的参数保存
				//------------------------------------------------------------------
				document.getElementById("result").innerHTML = "底图生成完成 。";
			}
			else
				document.getElementById("result").innerHTML = xmlhttp.status + xmlhttp.statusText;
		}
		else{
			document.getElementById("result").innerHTML = "正在生成底图 ......";
		}
	};
	
	xmlhttp.onreadystatechange = cbfunc;
	xmlhttp.open("POST",url,true);//中文要用urlEncode
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(para);
}

var originalColor;

function svgmouseover(th){
	originalColor = th.getAttribute("fill");
	th.setAttribute("fill","orange");
	th.setAttribute("stroke","yellow");
	th.setAttribute("stroke-width","0.15");
}

function svgmouseout(th){
	th.setAttribute("fill",originalColor);
	th.setAttribute("stroke","black");
	th.setAttribute("stroke-width","0.1");
}

function svgmousemove(th,event){
	event=event||window.event;   
    //var th=event.target||event.srcElement;      
    alert(event.clientX+","+event.clientY);
}

function changeColors(series){
	if(series=="0"){
		var i;
		for(i=0;i<document.getElementById("SvgElement").childNodes.length;i++){
			document.getElementById("SvgElement").childNodes[i].setAttribute("fill","none");
		}
	}
	else{
		var xmlhttp;
		if(window.XMLHttpRequest)
			xmlhttp = new XMLHttpRequest();
		else
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
		var url = "svgColorAction.m";
		var number = document.getElementById("SvgElement").childNodes.length;
		var para = "series="+series+"&number="+number;
		cbfunc = function(){
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					var colorres = xmlhttp.responseText;
					var colorlist = colorres.split(",");
					var i;
					for(i=0;i<colorlist.length;i++){
						if(document.getElementById("SvgElement").childNodes[i].getAttribute("id")!="8888")
							document.getElementById("SvgElement").childNodes[i].setAttribute("fill",colorlist[i]);
					}
					document.getElementById("result").innerHTML = "色系改变完成。";
				}
				else
					document.getElementById("result").innerHTML = xmlhttp.status + xmlhttp.statusText;
			}
			else{
				document.getElementById("result").innerHTML = "正在改变色系 ......";
			}
		};
		
		xmlhttp.onreadystatechange = cbfunc;
		xmlhttp.open("POST",url,true);//中文要用urlEncode
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send(para);
	}
}

function uploadExcel(){
	var filePath = document.getElementById("upload_file").value;
	alert(filePath);
	if (filePath == "")
	{
		document.getElementById("result").innerHTML = "请选择要上传的文件!";
	    return false;
	}
	
	var t1 = filePath.lastIndexOf("\\");  
	var t2 = filePath.lastIndexOf(".");   
	var fileName = filePath.substring(t1 + 1, t2); 
	var fileType = filePath.substring(t2 + 1, filePath.length); 
	   
	fileType = fileType.toLowerCase();	
	if (fileType!="xls" && fileType!="xlsx"){
		document.getElementById("result").innerHTML = "只允许上传xls/xlsx文件!";
		document.getElementById("upload_file").focus();
		return false;
	}
	
	var xmlhttp;
	if(window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	var url = "dataXMLAction.m";	
    var oOutput = document.getElementById("result"); 
    var oData = new FormData(); 
    var uploadFile = document.getElementById("upload_file").files[0];
    var dataTypeS = document.getElementById("select_file");
    var dataType = dataTypeS.options[dataTypeS.options.selectedIndex].value;
    
    alert(oData+uploadFile);
  
    oData.append("uploadFile",uploadFile);
    oData.append("dataType",dataType);
    oData.append("fileName", fileName); 
    oData.append("fileType", fileType); 
    
    cbfunc = function(){
		if(xmlhttp.readyState == 4){
			if(xmlhttp.status == 200){				
				oOutput.innerHTML = "文件上传完成。";
			}
			else
				oOutput.innerHTML = xmlhttp.status + xmlhttp.statusText;
		}
		else{
			oOutput.innerHTML = "正在上传文件......";
		}
	};	
	xmlhttp.onreadystatechange = cbfunc;
 
	xmlhttp.open("POST", url, true); 
	xmlhttp.setRequestHeader("Content-type","multipart/form-data;boundary=---------------------------" + new Date().getTime());
    xmlhttp.send(oData); 
}